package com.yupi.project.mq.deadQueue;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

/**
 * @author <a href=""https://github.com/Fzs0>逢左使</a>
 * @create 2024/01/07 15:34
 * @Description: 生产者
 */
public class Producer {

    /**
     * 设置队列名称
     */
    private static final String NORMAL_ROUTING_KEY = "normal";
    private static final String NORMAL_EXCHANGE = "normal_exchange";

    public static void main(String[] args) throws Exception {
        // 获取Channel
        Channel channel = RabbitMQUtils.getChannel();

        channel.exchangeDeclare(NORMAL_EXCHANGE, BuiltinExchangeType.DIRECT);

        AMQP.BasicProperties properties = null;
        // 加上过期时间
        properties = new AMQP.BasicProperties().builder().expiration("8000").build();

        for (int i = 1; i < 11; i++) {
            String message = "info" + i;
            channel.basicPublish(NORMAL_EXCHANGE, NORMAL_ROUTING_KEY, properties, message.getBytes());
        }
        System.out.println("消息发送完毕");
    }

}
